// components/searchBox/searchBox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    resourceType: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {

      }
    },
    defaultValue: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {

      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    InputValue:""
  },

  /**
   * 组件的方法列表
   */
  methods: {
    inputFocus:function(){
      // if (this.properties.resourceType === "contestList"){
      //   wx.navigateTo({
      //     url: '/pages/search/search',
      //   })
      // }
    },
    searchInput:function(e){
      this.setData({
        InputValue:e.detail.value
      })
    },
    clearText:function(){
      this.setData({
        InputValue: ''
      })
    },
    handlerSearch:function(e){
      let value = e.detail.value;
      if(!value){
        return;
      }
      
      if (this.properties.resourceType === "contestList"){
        setTimeout(()=>{
          this.setData({
            InputValue: ""
          })
        },1000)
        wx.navigateTo({
          url: `/pages/search/search?searchValue=${value}`,
        })
      }else{
        this.triggerEvent('handlerSearch', { value: value });
      }
        
    }
  }
})
